from tkinter import *
from tkinter.ttk import *
import win32con
import win32api
from AutoWifi import AutoWifi

username = ""
password = ""
ISP = ""
class WinGUI(Tk):
    def __init__(self,uninstall_lock = "./"):
        self.uninstall_lock = uninstall_lock
        super().__init__()
        self.__win()
        self.tk_input_lne98c9a = self.__tk_input_lne98c9a(self)
        self.tk_label_lne99pcz = self.__tk_label_lne99pcz(self)
        self.tk_input_lne9b05j = self.__tk_input_lne9b05j(self)
        self.tk_label_lne9by60 = self.__tk_label_lne9by60(self)
        self.tk_select_box_lne9dmty = self.__tk_select_box_lne9dmty(self)
        self.tk_label_lne9eejr = self.__tk_label_lne9eejr(self)
        self.tk_button_lne9ew9b = self.__tk_button_lne9ew9b(self)
        self.tk_label_frame_lne9pea4 = self.__tk_label_frame_lne9pea4(self)
    def __win(self):
        self.title("AutoWifi")
        # 设置窗口大小、居中
        width = 800
        height = 500
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        self.resizable(width=False, height=False)
        # 自动隐藏滚动条
    def scrollbar_autohide(self,bar,widget):
        self.__scrollbar_hide(bar,widget)
        widget.bind("<Enter>", lambda e: self.__scrollbar_show(bar,widget))
        bar.bind("<Enter>", lambda e: self.__scrollbar_show(bar,widget))
        widget.bind("<Leave>", lambda e: self.__scrollbar_hide(bar,widget))
        bar.bind("<Leave>", lambda e: self.__scrollbar_hide(bar,widget))

    def __scrollbar_show(self,bar,widget):
        bar.lift(widget)
    def __scrollbar_hide(self,bar,widget):
        bar.lower(widget)

    def vbar(self,ele, x, y, w, h, parent):
        sw = 15 # Scrollbar 宽度
        x = x + w - sw
        vbar = Scrollbar(parent)
        ele.configure(yscrollcommand=vbar.set)
        vbar.config(command=ele.yview)
        vbar.place(x=x, y=y, width=sw, height=h)
        self.scrollbar_autohide(vbar,ele)
    def __tk_input_lne98c9a(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=201, y=20, width=581, height=57)
        return ipt
    def __tk_label_lne99pcz(self,parent):
        label = Label(parent,text="学工号",anchor="center", )
        label.place(x=20, y=20, width=160, height=59)
        return label
    def __tk_input_lne9b05j(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=201, y=100, width=580, height=56)
        return ipt
    def __tk_label_lne9by60(self,parent):
        label = Label(parent,text="密码(身份证后六位)",anchor="center", )
        label.place(x=20, y=100, width=158, height=58)
        return label
    def __tk_select_box_lne9dmty(self,parent):
        cb = Combobox(parent, state="readonly", )
        cb['values'] = ("移动","电信","联通","单宽","内网")
        cb.place(x=200, y=180, width=583, height=41)
        return cb
    def __tk_label_lne9eejr(self,parent):
        label = Label(parent,text="运营商",anchor="center", )
        label.place(x=20, y=180, width=159, height=42)
        return label
    def __tk_button_lne9ew9b(self,parent):
        btn = Button(parent, text="确定提交", takefocus=False,)
        btn.place(x=20, y=260, width=760, height=38)
        return btn

    def __tk_label_frame_lne9pea4(self, parent):
        frame = LabelFrame(parent,
                           text="""
请认真阅读信息 \n      
本程序可以开机自动连接校园网,请填写正确学工号与密码,请在连接Wifi(就是连接Wifi但是还没有登录认证时)后运行本程序 \n
如果连接成功依然没有网络可以尝试进入网站是否可以访问,不能访问则很可能是学工号或者密码没有填写正确 \n
若想要卸载此程序只需要删除"""+self.uninstall_lock+"""文件再重启即可 \n         
本程序由数科231张一风制作,不会盗取你的任何信息请放心食用,喜欢音乐的朋友可以找我做伴奏,微信:zyf3164689822""",)
        frame.place(x=20, y=310, width=765, height=200)
        return frame

    def execInit(self):
        global username
        global password
        global ISP
        username = self.tk_input_lne98c9a.get()
        password = self.tk_input_lne9b05j.get()
        ISP = self.tk_select_box_lne9dmty.get()
        if (username == ""): win32api.MessageBox(0,'学工号不能为空!!!', 'AutoWifi提示', win32con.MB_OK|win32con.MB_ICONEXCLAMATION)
        elif (password == ""): win32api.MessageBox(0,'密码不能为空!!!', 'AutoWifi提示', win32con.MB_OK|win32con.MB_ICONEXCLAMATION)
        elif (ISP == ""): win32api.MessageBox(0,'运营商不能为空!!!', 'AutoWifi提示', win32con.MB_OK|win32con.MB_ICONEXCLAMATION)
        AutoWifi().intoFile()

class Win(WinGUI):
    def __init__(self):
        super().__init__()
        self.__event_bind()
    def execInit(self,evt):
        super().execInit()

    def __event_bind(self):
        self.tk_button_lne9ew9b.bind('<Button-1>',self.execInit)
        pass

